<template>
    <div class="form-horizontal" role="form">
      <div class="form-group">
        <div class="col-sm-6">
          <label>Date</label>
          <input type="Date" class="form-control" placeholder="Date" v-model="date">
        </div>
        
        <div class="col-sm-6">
          <label>Hours</label>
          <input type="Number" class="form-control" placeholder="Hours" v-model="hours">
        </div>
        
      </div>
      <div class="form-group">
        <div class="col-sm-12">
          <label>Comment</label>
          <input type="Text" class="form-control" placeholder="Comment" v-model="comment">
        </div>
      </div>
      

      <div class="form-group">
        <div class="col-sm-12">
          <div class="pull-right">
            <button class="btn btn-primary" @click="save">Save</button>
            <router-link to="/time-entries" class="btn btn-danger">Cancel</router-link>
          </div>
        </div>
      </div>
    </div>
</template>

<script>
    export default {
      data () {
        return {
          date: '',
          hours: '',
          comment: ''
        }
      },
      methods: {
        save () {
          const task = {
            date: this.date,
            totalTime: this.hours,
            comment: this.comment
          }

          // 添加总时间
          this.$store.dispatch('incTotalTime', this.hours)
          // 添加该计划
          this.$store.dispatch('addTask', task)

          this.$router.go(-1);
        }
      }
    }
</script>

<style scoped>

</style>